package mipo.top.system.controller;


import mipo.top.base.util.JsonResult;
import mipo.top.base.util.PageUtil;
import mipo.top.system.domain.Role;
import mipo.top.system.query.RoleQuery;
import mipo.top.system.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private IRoleService roleService;

    @GetMapping
    public List<Role> sad(){
        return roleService.findall();
    }

    @PutMapping
    public JsonResult su(@RequestBody Role role){
        try {
            if(role.getId()==null){
                roleService.save(role);
            }else{
                roleService.update(role);
            }
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("错误数据");
        }
    }

    @DeleteMapping("/{id}")
    public void adw(@PathVariable("id") Long id){
        roleService.remove(id);
    }

    @PostMapping
    public PageUtil<Role> asp(@RequestBody RoleQuery roleQuery){
        return roleService.queryData(roleQuery);
    }
    @PatchMapping
    private void bacthDel(@RequestBody List<Long> ids){
        roleService.patchremove(ids);
    }
}
